package com.zengshuai.miniprogrambackend.Controller;

import com.zengshuai.miniprogrambackend.Entity.RecyleOrder;
import com.zengshuai.miniprogrambackend.Mapper.RecycleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/recycle")
public class RecycleController {

    @Autowired
    private RecycleMapper recycleMapper;


    @GetMapping("/saverecycleorder")
    public void saverecycleorder(String recyclename, String desc, String address, String openid, String booktime, String telnumber) {


        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
        String currentTime = simpleDateFormat.format(new Date());

        recycleMapper.saveRecycleOrder(openid, address, booktime, currentTime, desc, recyclename, telnumber);


    }




    @GetMapping("/getrecycleorderlist")
    public List<RecyleOrder> getrecycleorderlist() {


        return recycleMapper.getrecycleorderlist();
    }


    @GetMapping("/getrecycleorderlistbystatus")
    public List<RecyleOrder> getrecycleorderlistbystatus(String status) {

        System.out.println(status);


        return recycleMapper.getrecycleorderlistbystatus(status);

    }



    @GetMapping("/acceptorder/{id}")
    public void acceptorder(@PathVariable("id") String id) {

        recycleMapper.acceptorder(id);


    }

    @GetMapping("/arrive/{id}")
    public void arrive(@PathVariable("id") String id) {

        recycleMapper.arrive(id);


    }


    @GetMapping("/jiesuan")
    public void jiesuan(String id,String recycleprice ) {
        System.out.println(id);
        System.out.println(recycleprice);
        recycleMapper.jiesuan(id,recycleprice);


    }





}
